﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace JRBase
{
    public class MapSprite : Sprite
    {
        public Rectangle Window { get; set; }

        public void Initialize(Texture2D texture)
        {
            base.active = true;
            this.texture = texture;
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            if (base.active)
            {
                int allTexturesSize = texture.Width;
                int windowEnd = Window.X + Window.Width;
                int noTextureWidth = windowEnd - allTexturesSize;
                spriteBatch.Draw(texture, Vector2.Zero, Window, Color.White);
                while (noTextureWidth > 0)
                {
                    allTexturesSize += texture.Width;
                    int drawStart = Window.Width - noTextureWidth;
                    if (drawStart < 0)
                    {
                        drawStart = 0;
                    }
                    Vector2 vec = new Vector2(drawStart, 0);

                    int relWinX = Window.X - (allTexturesSize - texture.Width);
                    if(relWinX < 0)
                    {
                        relWinX = 0;
                    }
                    Rectangle relWindow = new Rectangle(relWinX, Window.Y, Window.Width, Window.Height);
                    spriteBatch.Draw(texture, vec, relWindow, Color.White);
                    noTextureWidth = windowEnd - allTexturesSize;
                }
                
            }
        }

        public override void Update(GameTime gameTime)
        {

        }
    }
}
